package com.cheung.leetcode.contest.week.week406;

import lyroot.entity.ListNode;

import java.util.HashSet;
import java.util.Set;

/**
 * @BelongsProject : java-leetcode
 * @BelongsPackage : com.cheung.leetcode.contest.week406
 * @Author :  cheungming
 * @CreateTime : 2024-07-14 10:43:53
 * @Description : 竞赛100368
 * @Version : 1.0
 */
public class Code100368Test {


    public ListNode modifiedList(int[] nums, ListNode head) {


        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }

        ListNode temp = new ListNode(-1);
        temp.next = head;

        ListNode pre = temp;
        while (pre.next != null) {
            if (set.contains(pre.next.val)) {
                pre.next = pre.next.next;
            } else {
                pre = pre.next;
            }
        }

        return temp.next;
    }


    public static void main(String[] args) {
        int[] nums = {1, 3};
        ListNode head = new ListNode(1);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(3);
        ListNode node4 = new ListNode(4);
        ListNode node5 = new ListNode(5);
        head.next = node2;
        node2.next = node3;
        node3.next = node4;
        node4.next = node5;
        System.out.println(new Code100368Test().modifiedList(nums, head));
    }
}
